package com.tools.config;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author wangminggen
 */
@Slf4j
@Configuration
@RequiredArgsConstructor
public class AuthConfiguration implements WebMvcConfigurer {
    private static final String[] STATIC_RESOURCE = {
            "/**/*.html",
            "/**/*.css",
            "/**/*.js",
            "/**/*.ico",
            "/**/*.jpg",
            "/**/*.png",
            "/**/*.gif",
            "/**/*.ttf",
            "/webSocket/**"
    };

    @Bean
    AuthFilterWitheURLConfigure authConfigure(ApplicationContext applicationContext) {
        return new AuthFilterWitheURLConfigureImpl(applicationContext)
                .antMatchers(HttpMethod.GET, STATIC_RESOURCE).permitAll()
                .antMatchers("/manifest.json").permitAll()
                .antMatchers("/robots.txt").permitAll()
                .antMatchers("/swagger-ui.html").permitAll()
                .antMatchers("/swagger-resources/**").permitAll()
                .antMatchers("/webjars/**").permitAll()
                .antMatchers("/*/api-docs").permitAll()
                .antMatchers("/druid/**").permitAll();
    }
}
